﻿using System.Collections.Specialized;
using System.Web;
using ElectronicCommerce.Framework.Configuration;
using ElectronicCommerce.Framework.Data.Configuration;
using ElectronicCommerce.Framework.Utility;
using ElectronicCommerce.Framework.Web.Configuration.Cookie;
using ElectronicCommerce.Framework.Web.Configuration.ImageSize;
using ElectronicCommerce.Framework.Web.Configuration.Resource;
using ElectronicCommerce.Framework.Web.Configuration.StringResource;
using ElectronicCommerce.Framework.Web.Configuration.StringResource.Help;
using ElectronicCommerce.Framework.Web.Configuration.StringResource.HtmlBlock;
using ElectronicCommerce.Framework.Web.Configuration.StringResource.List;
using ElectronicCommerce.Framework.Web.Configuration.Upload;
using ElectronicCommerce.Framework.Web.Configuration.Website;

namespace ElectronicCommerce.Framework.Web.Configuration
{
    public class ConfigHelper
    {
        #region Website Configuration

        public static SiteConfig WebsiteConfig
        {
            get { return ConfigManager.GetConfig<WebsiteConfiguration>().WebSiteConfig; }
        }

        public static ConnectionStringConfigs ConnectionStringConfigs
        {
            get { return ConfigManager.GetConfig<ConnectionStringConfigs>(); }
        }

        public static ResourceSiteConfig ResourceSiteConfig
        {
            get { return ConfigManager.GetConfig<WebsiteConfiguration>().ResourceSiteConfig; }
        }

        public static SiteConfig ProductImageSiteConfig
        {
            get { return ConfigManager.GetConfig<WebsiteConfiguration>().ProductImageSiteConfig; }
        }

        public static FileStoreSiteConfig FileStoreSiteConfig
        {
            get { return ConfigManager.GetConfig<WebsiteConfiguration>().FileStoreSiteConfig; }
        }


        public static SiteConfig BrandLogoSiteConfig
        {
            get { return ConfigManager.GetConfig<WebsiteConfiguration>().BrandLogoSiteConfig; }
        }

        public static SiteConfig BannerSiteConfig
        {
            get { return ConfigManager.GetConfig<WebsiteConfiguration>().BannerSiteConfig; }
        }

        public static ThemeConfig ThemeConfig
        {
            get { return ConfigManager.GetConfig<WebsiteConfiguration>().ThemeConfig; }
        }

        public static Localization LocalizationConfig
        {
            get
            {
                Localization cfg = ConfigManager.GetConfig<WebsiteConfiguration>().LocalizationConfig;
                if (cfg.StoreCompanyCode == "0000")
                {
                    HttpContext ctx = HttpContext.Current;
                    if (ctx != null)
                    {

                        NameValueCollection nc = new NameValueCollection();
                        if (ctx.Request.Cookies["UserInfo"].IsNotNull()
                            && ctx.Request.Cookies["UserInfo"].Value.IsNotNull()
                            && ctx.Request.Cookies["UserInfo"].Value.IsNotEmpty())
                        {
                            nc = HttpUtility.ParseQueryString(ctx.Request.Cookies["UserInfo"].Value);

                            Localization innerConfig = new Localization();
                            if (nc["CompanyCode"].IsNotEmpty())
                            {
                                innerConfig.CompanyCode = nc["CompanyCode"];
                            }
                            if (nc["StoreCompanyCode"].IsNotEmpty())
                            {
                                innerConfig.StoreCompanyCode = nc["StoreCompanyCode"];
                            }
                            if (nc["LanguageCode"].IsNotEmpty())
                            {
                                innerConfig.LanguageCode = nc["LanguageCode"];
                            }

                            cfg = innerConfig;
                        }
                    }
                }
                return cfg;
            }
        }

        public static WebSiteInfoConfig WebSiteInfoConfig
        {
            get { return ConfigManager.GetConfig<WebSiteInfoConfig>(); }
        }
        #endregion

        public static CookieConfiguration CookieConfig
        {
            get { return ConfigManager.GetConfig<CookieConfiguration>(); }
        }

        public static PageConfiguration PageConfig
        {
            get { return ConfigManager.GetConfig<PageConfiguration>(); }
        }

        public static FrontPageConfiguration FrontPageConfig
        {
            get { return ConfigManager.GetConfig<FrontPageConfiguration>(); }
        }

        public static JavascriptConfiguration JavascriptConfig
        {
            get { return ConfigManager.GetConfig<JavascriptConfiguration>(); }
        }

        public static CssConfiguration CssConfig
        {
            get { return ConfigManager.GetConfig<CssConfiguration>(); }
        }

        public static StringResourceConfiguration StringResourceConfig
        {
            get { return ConfigManager.GetConfig<StringResourceConfiguration>(); }
        }

        public static PagePropertiesConfiguration PagePropertiesConfig
        {
            get { return ConfigManager.GetConfig<PagePropertiesConfiguration>(); }
        }
        /// <summary>
        /// Gets the current <see cref="ElectronicCommerce.Framework.Web.Configuration.HtmlBlockResourceConfiguration"/>
        /// </summary>
        public static HtmlBlockResourceConfiguration HtmlBlockConfig
        {
            get { return ConfigManager.GetConfig<HtmlBlockResourceConfiguration>(); }
        }

        /// <summary>
        /// Gets the current <see cref="ElectronicCommerce.Framework.Web.Configuration.ListConfiguration"/>
        /// </summary>
        public static ListConfiguration ListConfig
        {
            get { return ConfigManager.GetConfig<ListConfiguration>(); }
        }

        /// <summary>
        /// Gets the params config.
        /// </summary>
        public static ParamsConfiguration ParamsConfig
        {
            get { return ConfigManager.GetConfig<ParamsConfiguration>(); }
        }

        public static HelpResourceConfiguration HelpConfig
        {
            get { return ConfigManager.GetConfig<HelpResourceConfiguration>(); }
        }

        public static HelpCategoryResourceConfiguration HelpCategoryConfig
        {
            get { return ConfigManager.GetConfig<HelpCategoryResourceConfiguration>(); }
        }

        public static LeftNavigationConfig LeftNavigationConfig
        {
            get { return ConfigManager.GetConfig<LeftNavigationConfig>(); }
        }

        public static ImageSizeConfiguration ImageSizeConfig
        {
            get { return ConfigManager.GetConfig<ImageSizeConfiguration>(); }
        }

        //public static OWSServiceAddressConfiguration OWSConfig
        //{
        //    get { return ConfigManager.GetConfig<OWSServiceAddressConfiguration>(); }
        //}


        public static UploadConfiguration UploadConfig
        {
            get { return ConfigManager.GetConfig<UploadConfiguration>(); }
        }


        public static FixSqlConfig FixSqlConfig
        {
            get { return ConfigManager.GetConfig<FixSqlConfig>(); }
        }

        public static SeoConfiguration SeoConfig
        {
            get { return ConfigManager.GetConfig<SeoConfiguration>(); }
        }


    }
}
